﻿using Microsoft.WindowsAzure.Storage.Table;
using SimplePersonManager.Contracts;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace SimplePersonManager.DataAccess
{
    internal class PersonEntity : TableEntity
    {
        public string Name { get; set; }
        public DateTime Born { get; set; }
        public string City { get; set; }
        public string Post_Code { get; set; }
        public string Country { get; set; }

        internal static PersonEntity FromPerson(Person person)
        {
            var personEntity = new PersonEntity();

            personEntity.PartitionKey   = person.City;
            personEntity.RowKey         = person.Name;

            personEntity.Name           = person.Name;
            personEntity.Born           = person.Born;
            personEntity.City           = person.City;
            personEntity.Post_Code      = person.Post_Code;
            personEntity.Country        = person.Country;
            
            return personEntity;
        }

        internal Person ToPerson()
        {
            var person = new Person();

            person.Born       = Born;
            person.City       = City;
            person.Country    = Country;
            person.Name       = Name;
            person.Post_Code  = Post_Code;

            return person;
        }
    }
}
